package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.SysRoleDTO;
import com.itheima.advantagesup.service.SysRoleService;
import com.itheima.advantagesup.vo.SysRoleVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户角色控制器
 *
 * @author liudo
 * @version 1.0
 * @project advantages-up
 * @date 2023/9/11 21:18:26
 */
@RestController
@RequestMapping("/sys_role")
@RequiredArgsConstructor
public class SysRoleController {

    private final SysRoleService sysRoleService;

    /**
     * 列表
     *
     * @param page  页
     * @param limit 限度
     * @param name  名称
     * @return {@link R}<{@link PageBean}<{@link SysRoleVO}>>
     */
    @GetMapping("/list")
    public R<PageBean<SysRoleVO>> list(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer limit,
                                       String name) {

        PageBean<SysRoleVO> pageBean = sysRoleService.list(page, limit, name);
        return R.success(pageBean);
    }

    /**
     * 所有数据
     *
     * @return {@link R}<{@link List}<{@link SysRoleVO}>>
     */
    @GetMapping("/allData")
    public R<List<SysRoleVO>> allData() {
        List<SysRoleVO> sysRoleVOS = sysRoleService.allData();
        return R.success(sysRoleVOS);
    }

    /**
     * 添加
     *
     * @param sysRoleDTO sys角色添加dto
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody SysRoleDTO sysRoleDTO) {
        sysRoleService.add(sysRoleDTO);
        return R.success();
    }

    /**
     * 行信息
     *
     * @param id id
     * @return {@link R}<{@link SysRoleVO}>
     */
    @GetMapping("/rowInfo")
    public R<SysRoleVO> rowInfo(String id) {
        SysRoleVO sysRoleVO = sysRoleService.rowInfo(id);
        return R.success(sysRoleVO);
    }

    /**
     * 使现代化
     *
     * @param sysRoleDTO 系统角色dto
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/update")
    public R<?> update(@RequestBody SysRoleDTO sysRoleDTO) {
        sysRoleService.update(sysRoleDTO);
        return R.success();
    }

    /**
     * del
     *
     * @param id id
     * @return {@link R}<{@link ?}>
     */
    @GetMapping("/del")
    public R<?> del(String id) {
        sysRoleService.deleteById(id);
        return R.success();
    }

}
